package service;

import dao.NavigatorDAOImpl;
import dao.PilotDAOImpl;
import logic.Navigator;
import logic.Pilot;
import org.jboss.logging.annotations.Pos;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import java.util.List;
import java.util.Map;

/**
 * Created by Vovancho on 08.12.2014.
 */
@ManagedBean
@ViewScoped
public class NavigatorServiceImpl extends Navigator  {

    private NavigatorDAOImpl navigatorDAOI = new NavigatorDAOImpl();
    private List<Navigator> navigators;

    public List<Navigator> getNavigators() {
        return navigators;
    }

    public void setNavigators(List<Navigator> navigators) {
        this.navigators = navigators;
    }

    public void addNavigator() {
        navigatorDAOI.addNavigator(new Navigator(getFirstName(), getMiddleName(), getLastName()));
    }
//@PostConstruct
    public List<Navigator> listNavigator() {
        return navigatorDAOI.listNavigator();
    }

    public List<Navigator> navigatorById(int navigatorId){
        return navigatorDAOI.getNavigatorById(navigatorId);
    }

    public void removeNavigator() {
        FacesContext context = FacesContext.getCurrentInstance();
        Map<String, String> map = context.getExternalContext().getRequestParameterMap();
        Integer id = new Integer(map.get("navigatorId"));
        navigatorDAOI.removeNavigator(id);
    }
}
